package com.aote.expression.paramprocessor;

import java.util.Map;

import com.aote.expression.Param;
import com.aote.util.SingleValueHelper;
import com.browsesoft.htmlcomponent.HTMLBasicComponent;
import com.browsesoft.user.User;

/**
 * 根据配置的单值，产生编号，然后回写到单值
 * 
 * @author Administrator
 */
public class ProSerialNumberProcessor implements ParamProcessor {

	public String process(Param param, Map attribures, User loginUser,
			HTMLBasicComponent component) {
		Map map = param.getParams();
		String name = (String) map.get("name");
		// 原来的字段
		String base = (String) map.get("base");
		String result = "";
		if (attribures.containsKey(name)) {
			name = (String) attribures.get(name);
			result = SingleValueHelper.getStringValue(name);
			int i = Integer.parseInt(result);
			String value = i + 1 + "";
			return value;
		}
		return (String)attribures.get(base);
	}

	/**
	 * 判断是否更新后台单值
	 * 
	 * @return bool
	 */
	private boolean ifUpdateSingleValue(String result, String base,
			Map attribures) {
		boolean flag = false;
		if (!attribures.containsKey(base) || attribures.get(base).equals("")) {
			flag = true;
		}else{
			flag = false;
		}
		return flag;
	}

}
